<template>
  <div class="wrap">
    <el-table :data="tableData" style="width: 100%" v-loading="loading">
      <el-table-column prop="title" label="主题" width="180"> </el-table-column>
      <el-table-column prop="teacher" label="主讲老师" width="180">
      </el-table-column>
      <el-table-column prop="address" label="所属课程">
        <template slot-scope="{ row }">
          <span>{{ row.sysCourse ? row.sysCourse.title : '暂无数据' }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="status" label="状态">
        <template slot-scope="{ row }">
          <span v-show="row.status == 0">暂存</span>
          <span v-show="row.status == 1">显示</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="250" fixed="right">
        <template slot-scope="{ row }">
          <el-button-group>
            <el-button
              type="primary"
              size="mini"
              v-if="!row.eduSignIn"
              @click="handleSignIn(row)"
              >开启签到</el-button
            >
            <el-button
              type="primary"
              size="mini"
              v-if="row.eduSignIn"
              @click="handleSignList(row)"
              >签到列表</el-button
            >
            <el-button type="danger" size="mini" @click="handleDelete(row)"
              >删除</el-button
            >
          </el-button-group>
        </template>
      </el-table-column>
      <div slot="empty" class="emptyBg">
        <el-empty :image-size="200"></el-empty>
      </div>
    </el-table>
    <Pagination
      v-show="parseInt(pageObj.count) > 0"
      :total="parseInt(pageObj.count)"
      @change="getList"
      :page.sync="listQuery.page"
      :limit.sync="listQuery.limit"
    />
  </div>
</template>
<script>
import {
  eduTeachingCourseQuery,
  eduTeachingCourseDelete,
} from '@/api/admin/teach/eduTeachingCourse.js'
import Bus from '@/utils/bus.js'
export default {
  data() {
    return {
      loading: false,
      listQuery: {
        page: 1,
        limit: 10,
        eduTeachingId: undefined,
      },
      tableData: [],
      pageObj: {},
    }
  },

  mounted() {
    this.getList()
    Bus.$on('changeCourse', (id) => {
      this.listQuery.eduTeachingId = id
      this.tableData = []
      this.pageObj = {}
      this.getList()
      this.dialogVisible = true
    })
  },
  beforeDestroy() {
    Bus.$off('changeCourse')
  },
  methods: {
    async getList() {
      this.listQuery.eduTeachingId = this.$route.query.id
      this.loading = true
      let res = await eduTeachingCourseQuery(this.listQuery)
      this.tableData = res.data.data
      this.pageObj = res.data
      this.loading = false
    },
    //开启签到
    handleSignIn(row) {
      this.$bus.$emit('showDialogSignInAdd', row)
    },
    //签到列表
    handleSignList(row) {
      this.$bus.$emit('showDialogSigninPersonList', row)
    },
    //删除确认
    handleDelete(row) {
      this.$confirm('确定要删除吗?', '提示', {
        confirmButtonText: '删除',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(() => {
          this.delete(row)
        })
        .catch(() => {})
    },
    //删除
    delete(row) {
      eduTeachingCourseDelete(row.id).then((res) => {
        this.getList()
        this.$message({
          message: '操作成功',
          type: 'success',
        })
      })
    },
  },
}
</script>
<style scoped lang="scss">
.wrap {
  min-height: 500px;
}
</style>